import type { AxiosPromise } from "axios";
import type {
  EntityApi,
  EntityReq,
  EntityModel,
  EntityList,
  EntityKey,
} from "jmash-core";

// 接口
export interface ProcDefApi extends EntityApi {
  // 部署流程
  deployFlow(req: FlowDeployReq): AxiosPromise<FlowDeployRes>;
  // 部署流程XML
  deployFlowXml(xml: FlowDeployXmlReq): AxiosPromise<FlowDeployRes>;
  // 删除部署.
  deleteDeployment(deploymentId: string): AxiosPromise<boolean>;
  // 查询流程定义列表.
  findList?(query: ProcDefReq): AxiosPromise<FlowProcDefList>;
  // 查询流程定义
  findById?(key: ProcDefKey): AxiosPromise<FlowProcDefModel>;
  // 查询流程定义XML
  findProcDefXmlById(procDefId: string): AxiosPromise<string>;
  // 查询流程定义图片.
  findProcDefDiagram(procDefId: string): AxiosPromise;
}

// 查询
export interface ProcDefReq extends EntityReq {
  /**
   * 流程名称.
   */
  name?: string;
  /**
   * 流程Key.
   */
  key?: string;
  /**
   * 分类.
   */
  category?: string;
}

/**
 * 部署请求.
 */
export interface FlowDeployReq {
  //租户.
  tenant?: string;
  //请求ID.
  requestId?: string;
  //资源文件相对路径
  resFile?: string;
  //资源文件名称
  name?: string;
}

/**
 * 流程Xml部署请求.
 */
export interface FlowDeployXmlReq {
  /**
   * 用于检测重复请求的唯一字符串ID.
   */
  requestId?: string;
  /**
   * 资源文件XML.
   */
  xml?: string;
  /**
   * 流程名称.
   */
  name?: string;
}

/**
 * 流程部署回复.
 */
export interface FlowDeployRes {
  /**
   * 流程ID.
   */
  id?: string;
  /**
   * 流程名称.
   */
  name?: string;
  /**
   * 部署时间.
   */
  deploymentTime?: string;
  /**
   * 分类.
   */
  category?: string;
  /**
   * 租户ID.
   */
  tenantId?: string;
}

//流程定义Key.
export interface ProcDefKey extends EntityKey {
  //租户.
  tenant?: string;
  //流程定义ID.
  procDefId?: string;
}

/**
 * 流程定义列表.
 */
export interface FlowProcDefList extends EntityList {
  results: Array<FlowProcDefModel>;
}

/**
 * 流程定义.
 */
export interface FlowProcDefModel extends EntityModel {
  id: string;
  name: string;
  key: string;
  description?: string;
  version: number;
  resourceName?: string;
  deploymentId: string;
  diagramResourceName?: string;
  suspended: boolean;
  hasStartFormKey?: boolean;
  tenantId: string;
  children?: Array<FlowProcDefModel>;
}

// 主键
export interface HiProcinstKey extends EntityKey {
  id?: string;
}

export interface HiProcInstModel {
  //流程实例ID
  id?: string;
  // 业务Key
  businessKey?: string;
  // formKey
  formKey?: string;
}
